﻿using GN.Pay.Core.Entities;
using GN.Pay.Core.Exceptions;
using GN.Pay.Core.Values.Channel;
using GN.Pay.Core.Values.TradeTransfers;
using GN.Pay.TradeChannel;
using GN.Pay.TradeChannel.Transfers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Core
{
    /// <summary>
    /// 实体扩展
    /// </summary>
    public static class EntityExtensions
    {
        /// <summary>
        /// 创建订单查询结果
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static ITradeOrderQueryResult CreateOrderQueryResult(this QueueErrorMessage msg)
        {
            PayExceptionUtils.CheckNotNull(msg, nameof(msg));
            return msg.CreateResult<TradeOrderQueryResultValue>();
        }

        /// <summary>
        /// 创建退款申请结果
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static ITradeRefundApplyResult CreateRefundApplyResult(this QueueErrorMessage msg)
        {
            PayExceptionUtils.CheckNotNull(msg, nameof(msg));
            return msg.CreateResult<TradeRefundApplyResultValue>();
        }

        /// <summary>
        /// 创建转账申请结果
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static ITransfersApplyResult CreateTransfersApplyResult(this QueueErrorMessage msg)
        {
            PayExceptionUtils.CheckNotNull(msg, nameof(msg));
            return msg.CreateResult<TransfersApplyResult>();
        }


        /// <summary>
        /// 交易申请信息
        /// </summary>
        /// <param name="apply">申请</param>
        /// <returns></returns>
        public static ITransfersApplyInfo CreateTransfersApplyInfo(this TradeTransfersApply apply)
        {
            PayExceptionUtils.CheckNotNull(apply, nameof(apply));
            return new TransfersApplyInfo()
            {
                AccountName = apply.AccountName,
                AccountNo = apply.AccountNo,
                BankNo = apply.BankNo,
                ClientIp = apply.ClientIp,
                OpenBankName = apply.OpenBankName,
                ProvinceCity = apply.ProvinceCity,
                ServerIp = apply.AppIp,
                Summary = apply.Summary,
                TransfersMoney = apply.ApplyMoney,
                TransfersNo = apply.Id
            };
        }

        /// <summary>
        /// 交易申请信息
        /// </summary>
        /// <param name="apply">申请</param>
        /// <param name="transfersNo">转账号</param>
        /// <returns></returns>
        public static ITransfersApplyInfo CreateTransfersApplyInfo(this TradeTransfersApplyInfo apply, string transfersNo)
        {
            PayExceptionUtils.CheckNotNull(apply, nameof(apply));
            return new TransfersApplyInfo()
            {
                AccountName = apply.AccountName,
                AccountNo = apply.AccountNo,
                BankNo = apply.BankNo,
                ClientIp = apply.ClientIp,
                OpenBankName = apply.OpenBankName,
                ProvinceCity = apply.ProvinceCity,
                ServerIp = apply.AppIp,
                Summary = apply.Summary,
                TransfersMoney = apply.ApplyMoney,
                TransfersNo = transfersNo
            };
        }
    }
}
